#!/bin/make

CC=/usr/bin/clang
CFLAGS=-arch i386 -arch x86_64 -g -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -std=gnu99


PERLIN = _perlin.so
NOISEMETHOD = _noisemethod.so

BUILDDIR=build
PYTHONLIB_PATH = /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/noise

LIBNOISES=$(BUILDDIR)/_perlin.o $(BUILDDIR)/_noisemethod.o
MODULES = $(BUILDDIR)/$(PERLIN) $(BUILDDIR)/$(NOISEMETHOD)



all: dir $(MODULES)

dir:	
	mkdir -p $(BUILDDIR)

%.so: %.o
	$(CC) -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -g $^ -o $@
	cp $@ $(PYTHONLIB_PATH)

build/%.o: %.c	
	$(CC) -fno-strict-aliasing -fno-common -dynamic $(CFLAGS) -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c $^ -o $@ -funroll-loops

clean:
	rm -f $(LIBNOISES)

distclean:
	rm -f $(LIBNOISES) $(MODULES)	